import numpy as np

# 创建示例数组
arr = np.arange(12)
print("原始数组:", arr)

# 改变形状
reshaped = arr.reshape(3,4)
print("重塑为3x4:\n", reshaped)

# 转置

transposed = reshaped.T
print("转置:\n", transposed)

# 展平
flattened = reshaped.flatten()
print("展平:\n", flattened)

# 连接数组
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
concatenated = np.concatenate((a, b), axis=0)
print("垂直连接:\n", concatenated)
print("水平连接:\n", np.concatenate((a, b), axis=1))

# 堆叠
stacked_h = np.hstack((a, a))
stacked_v = np.vstack((a, a))
print("水平堆叠:\n", stacked_h)
print("垂直堆叠:\n", stacked_v)